package com.kuang;

import org.junit.Test;

import java.io.*;

/**
 * ClassName: BufferedTest
 * Description:
 * Date: 2021/3/17 15:26
 * Company: TravelSky
 *
 * @author YangXin
 */
public class BufferedTest {

    @Test
    public void  test() throws IOException {

        File file = new File("src\\main\\resources\\imgs\\微信截图_20210311203000.png");
        File file1 = new File("src\\main\\resources\\imgs\\缓冲流.png");
        //造节点流
        FileInputStream fis = new FileInputStream(file);
        FileOutputStream fos = new FileOutputStream(file1);
        //造缓冲流
        BufferedInputStream bis = new BufferedInputStream(fis);
        BufferedOutputStream bos = new BufferedOutputStream(fos);

        byte[] bytes = new byte[10];
        int len;
        while ((len = bis.read(bytes)) != -1){
            bos.write(bytes,0,len);
        }
        //资源关闭
        //要求先关闭外层的流,再关里面   外层流关闭的同时,内层流自动关闭
        bos.close();
        bis.close();
        fis.close();
        fos.close();
    }
}
